<template>
  <div class="acc-button">
    <div v-if="type !== 'done'" class="btn">
      <span v-for="item in showList" :key="item.id">
        <el-dropdown v-if="item.id === 'maintain'" @command="handleClick">
          <span class="el-dropdown-link acc-item">
            {{ item.title }}
            <i class="el-icon-arrow-down" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-for="item2 in item.children" :key="item2.id" :command="item2">{{ item2.title
            }}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <!-- 全屏icon 按钮 -->
         <span v-else-if='["siteList"].includes(item.id)' :style="{ 'margin-left': '10px','display':noshowIcon?'none':'block' }">
          <i class="el-icon-full-screen" style="font-size: 22px;color: #eb4b4b" @click="handleClick(item, true)" />
          <slot />
        </span>

        <el-button v-else class="pms-zr-button-primary pms-zr-ClosedBtn" size="small" @click="handleClick(item)">{{
          item.title }}</el-button>
        <!--        <span v-else class="acc-item" @click="handleClick(item)">{{ item.title }}</span>-->
      </span>
    </div>
    <el-dialog
      v-if="dialogVisible"
      ref="accDialog"
      :title="dialogTitle"
      :before-close="closeMaterialsDialog"
      :visible.sync="dialogVisible"
      class="pms-zr-dialog"
      :close-on-press-escape='!["materialBinding", "materialService","materialShow"].includes(item.id)'
      :append-to-body='!["materialShow"].includes(item.id)'
      :width="`${dialogWidth}%`"
    >
      <div style="max-height: 500px;overflow-y: auto">
        <component
          :is="dialogPage"
          :prj-id="prjId"
          :is-edit="isEdit"
          :select-list="selectList"
          @close="dialogVisible = false"
          @deviceDoNext="closeEquipmentChange"
        />
      </div>
    </el-dialog>
    <!-- 旧版弹框 -->
    <!-- <el-dialog
      title="提示"
      :visible.sync="dialogVisible2"
      class="pms-zr-dialog"
      :append-to-body='true'
      width="50%"
    >
      <div v-html='dialogMessage'></div>
      <span slot="footer" class="dialog-footer">
        <el-button   size="small" @click="dialogVisible2 = false">取 消</el-button>
        <el-button  size="small" type="primary" @click="dialogSubmit">确 定</el-button>
      </span>
    </el-dialog> -->
    <DialogConfirm v-if="dialogVisible2" :message="[dialogMessage]" @changeStatus="changeMsg" />
    <next-page
      v-if="nextVisible"
      ref="nextPage"
      :visible.sync="nextVisible"
      :activity-inst-id="workItem.activityInstID"
      :process-inst-id="workItem.processInstID"
      :activity-def-id="workItem.activityDefID"
      :process-def-name="workItem.processDefName"
      :loginName="loginName"
      :prj-id="newPrjDetail.prjId"
      route="1"
      @doNextEntity="nextPageRes"
    />
    <Back-page
      v-if="backVisible"
      ref="backPage"
      :visible.sync="backVisible"
      :process-inst-id="workItem.processInstID"
      :act-inset-id="workItem.activityInstID"
      :exclude-act-def-ids="excludeActDefIds"
      route="more"
      @doReturn="backPageRes"
    />

    <el-dialog
      v-if="checkDialog"
      :title="checkMaterials ? '物资服务总览' : '校验清单'"
      :visible.sync="checkDialog"
      :append-to-body="true"
      class="pms-zr-dialog"
      :width="checkMaterials ? '90%' : '50%'"
      :before-close="closeDialog"
      :check-materials="false"
    >
      <interior-verify :select-list="prjInfos" :check-materials="checkMaterials ? true : false" />
    </el-dialog>
  </div>
</template>
<script>
import plan from '@/views/acceptance/plan.vue'
import ZrPmsServiceTabs from '@/components/zr/ZrPmsServiceTabs.vue'
import materialService from '@/views/acceptance/materialService/index.vue'
import materialServiceDetail from '@/views/acceptance/materialService/detail.vue'
import DialogConfirm from '@/views/acceptanceManagement/materialServiceBind/components/dialogConfirm.vue'
import {
  beforeProdBindCheckApi,
  checkSerDetailsConfigApi, doNextBatchFLowApi, executeFailureToUpdateApi, executeVerificationApi,
  getGoToApi,
  getGoToMateApi,
  getVerificationListApi,
  threeSingleMatchApi,
  getGoToMultipleMateApi,
  getGoToMultiplApi,
  getStartEndWork, getShowEquipmentChangeApi, updateAcceptTimeApi,getSelectUser
} from '@/api/acceptance'
import interiorVerify from '../interior.vue'
import ZrMaterialService from '@/components/zr/ZrMaterialService.vue'
import Design from '@/views/acceptance/design.vue'
import siteList from '@/views/acceptance/components/siteList.vue'
import equipmentChange from '@/views/acceptance/components/equipmentChange.vue'
import { openPostWindow } from '@/utils/requestCommonForm'
import { clonePage, getQueryObject, msgInfoEl } from '@/utils'
import NextPage from '@/components/nextPerson/NextPage.vue'
import { backActivityApi, doNextFLowApi } from '@/api/acceptanceManagement/acceptanceMange'
import BackPage from '@/components/nextPerson/BackPage.vue'
import { Loading } from 'element-ui'
import { newOpenPostWindow } from '@/utils/newRequestCommonFormjs'
export default {
  name: 'AccButton',
  inject: ['prjDetail', 'workDetail'],
  components: {
    BackPage,
    NextPage,
    plan,
    Design,
    siteList,
    ZrPmsServiceTabs,
    interiorVerify,
    ZrMaterialService,
    materialService,
    materialServiceDetail,
    DialogConfirm,
    equipmentChange
  },
  props: {
    btnList: {
      type: Array,
      default: () => [],
      require: true
    },
    prjId: {
      type: String,
      default: '',
      require: true
    },
    selectList: {
      type: Array,
      default: () => [],
    }
  },
  data() {
    return {
      deepSelectList: [],
      show: false,
      isEdit: '0',
      checkDialog: false,
      item: {
        title: '设计监理标识修改',
        id: 'supervisor',
        type: 'dialog',
        url: 'design'
      },
      allList: [
        {
          title: '查看验工计价',
          id: 'checkValuation',
          type: 'goto',
          url: 'addInspectionValuation'
        },
        {
          title: '项目接维',
          id: 'maintenance',
          type: 'next',
          url: 'interiorVerify'
        },
        {
          title: '项目开工',
          id: 'projectStart',
          type: 'projectCheck',
          url: ''
        },
        {
          title: '项目完工',
          id: 'projectEnd',
          type: 'projectCheck',
          url: ''
        },
        {
          title: '绑定物资与服务',
          id: 'materialBinding',
          type: 'dialog',
          url: 'ZrMaterialService'
        },
        {
          title: '物资服务确认',
          id: 'materialService',
          type: 'dialog',
          url: 'ZrMaterialService'
        },
        {
          title: '物资与服务绑定查看',
          id: 'materialShow',
          type: 'dialog',
          url: 'materialService'
        },
        {
          title: '乙供物资明细配置',
          id: 'serviceEdit',
          type: 'dialog',
          url: 'ZrPmsServiceTabs'
        },
        {
          title: '乙供物资明细查看',
          id: 'serviceShow',
          type: 'dialog',
          url: 'ZrPmsServiceTabs'
        },
        {
          title: '资源录入',
          id: 'entering',
          type: 'goto',
          url: 'pushResourrceMateAndEntry'
        },
        // 类似下一步,选人提交流程
        {
          title: '项目交维申请',
          id: 'apply',
          type: 'next',
          url: 'interiorVerify'
        },
        // 类似下一步,选人提交流程
        {
          title: '项目内验',
          id: 'check',
          type: 'form',
          url: 'interiorVerify'
        },
        {
          // 单项信息确认的资源确认按钮
          title: '资源确认',
          id: 'materialAffirm',
          type: 'goto',
          url: 'getResourceConfirm'
        },
        {
          title: '申领/退库',
          id: 'materialApplyRetreat',
          type: 'goto',
          url: 'materialApplyRetreat'
        },
        {
          title: '验工计价',
          id: 'addValuation',
          type: 'goto',
          url: 'addInspectionValuation'
        },
        {
          title: '成本单信息',
          id: 'costSheet',
          type: 'goto',
          url: 'getCostSheetUrl'
        },
        {
          title: '设备变动信息',
          id: 'equipmentChange',
          type: 'dialog',
          url: 'equipmentChange'
        },
        {
          title: '三单一致性检查',
          id: 'threeOrders',
          type: 'message',
          url: 'threeSingleMatch'
        },
        {
          title: '运维监控信息查看',
          id: 'maintain',
          children: [
            {
              title: '运维实时性能查询',
              id: 'maintain1',
              type: 'goto',
              url: 'getOperationMonitorPerformance'
            },
            {
              title: '设备离线异常清单明细表查询',
              id: 'maintain2',
              type: 'goto',
              url: 'getOfflineDeviceList'
            },
            {
              title: 'FSU覆盖明细表查询',
              id: 'maintain3',
              type: 'goto',
              url: 'getFSUCoverDetail'
            },
            {
              title: '设备不准确异常清单明细表查询',
              id: 'maintain4',
              type: 'goto',
              url: 'getInaccurateEquipmentList'
            }
          ]
        },
        // 类似下一步,选人提交流程TODO
        {
          title: '发起内验',
          id: 'createCheck',
          type: 'next',
          url: 'interiorVerify'
        },
        {
          title: 'VR全景',
          id: 'panorama',
          type: 'goto',
          url: 'getPanoramaUrl'
        },
        {
          title: '设计监理标识修改',
          id: 'supervisor',
          type: 'dialog',
          url: 'design'
        },
        {
          title: '单项工程列表',
          id: 'siteList',
          type: 'dialog',
          url: 'siteList'
        },
        {
          title: '物资服务绑定总览',
          id: 'materialServiceShow',
          type: 'dialog',
          url: 'materialServiceDetail'
        }
      ],
      dialogVisible: false,
      dialogVisible2: false,
      dialogMessage: '',
      dialogList: ['serviceEdit'],
      goList: [],
      messageList: [],
      dialogPage: '',
      dialogWidth: 50,
      dialogTitle: '',
      checkList: {},
      currentCheck: {},
      nextVisible: false,
      backVisible: false,
      currentParams: [],
      type: '',
      excludeActDefIds: '',
      loading: '',
      materialsCode: '', // 新页面物资总览code
      checkMaterials: false, // 物资总览弹框是否打开
      saveCreateCheck: '',
      zgPrjList:[]
    }
  },
  computed: {
    showList() {
      return this.allList.filter(item => this.btnList.includes(item.id))
    },
    newPrjDetail() {
      return this.prjDetail()
    },
    newWorkDetail() {
      return this.workDetail()
    },
    workItem() {
      return {
        activityInstID: this.selectList[0].activityInstId,
        processInstID: this.selectList[0].processInstId,
        activityDefID: this.selectList[0].nodeId,
        processDefName: this.selectList[0].templateId
      }
    },
    prjInfos() {
      return this.selectList.map(item => {
        return {
          prjId: item.prjId,
          prjCode: item.prjCode,
          siteId: item.siteId,
          workItemId: item.workItemId,
          manageMode: item.manageMode,
          prjType: item.prjType,
          isNewBusiness: item.isNewBusiness,
          buildModes: item.buildModes,
          parentPrjId: item.parentPrjId,
          bizState: item.nodeState // 根据点击的按钮来决定
        }
      })
    },
    noshowIcon() {
      // 智联项目 整体 单项工程
      return (['1','2'].includes(this.newPrjDetail.isNewBusiness)||this.newPrjDetail.businessMajor==='04') && ['03', '31'].includes(this.newPrjDetail.manageMode)
    },
    loginName(){
      return  +this.newPrjDetail.isNewAcceptance === 1&&this.newWorkDetail.bizObject.bizState==='F12'&&this.zgPrjList?.confirm === 'Z'?this.newPrjDetail.projectManagerName :''
    }
  },
  created() {
    const { type } = getQueryObject()
    this.type = type
    window.addEventListener('message', (event) => {
      const base_url = ''
      if (event.origin === base_url) {
        return
      }
      if (event.data.type === 'initNextInfo') {
        if (!event.data.single) {
          this.materialsCode = event.data.doNext
          this.prefixCheck()
        }
      }
      if (event.data.type === 'materialServiceBind') {
        if (!this.show) {
          this.dialogVisible = false
        }
      }
      if (event.data.type === 'interiorVerify') {
        this.checkDialog = false
        this.$emit('getTable')
      }
    })
  },
  methods: {
    closeEquipmentChange(){
      console.log('接收到设备变更点下一步')
      this.dialogVisible = false
        setTimeout(()=>{
            this.nextVisible = true
        },100)
    },
    dialogEl(refName) {
      // 将弹框挂载在最外层
      const contentBody = window.top.document.body
      this.$nextTick(() => {
        const dialogModal = document.querySelector('.v-modal')
        console.log({ dialogModal })
        const elBody = this.$refs[refName].$el
        // dialogModal.style.zIndex = 2500
        // elBody.style.zIndex = 2501
        contentBody.appendChild(elBody)
        contentBody.appendChild(dialogModal)
        // disableScroll(contentBody)
      })
    },
    backPageRes(data) {
      const params = {
        'workItemId': this.selectList[0].workItemId,
        'opinion': data.opinion,
        'nextActDefId': data.nodeId, // 暂定
        'detailId': data.empId,
        'prjId': this.selectList[0].prjId
      }
      backActivityApi(params).then(res => {
        if (+res.code === 200) {
          if (this.newPrjDetail.manageMode == '31') {
            clonePage()
          } else {
            this.$message.success('操作成功')
            this.$emit('getTable')
          }
        }
      })
    },
    async prefixCheckList() {
      const params = {
        'prjId': this.selectList[0].prjId,
        'nodeState': this.selectList[0].nodeState
      }
      this.loading = Loading.service({
        lock: true,
        text: '正在处理,请稍后',
        spinner: 'el-icon-loading'
      })
      try {
        const result = await getVerificationListApi(params)
        this.checkList = result.data
        await this.prefixCheck()
      } finally {
        this.loading.close()
      }
    },
    // 确认下一步 getSelectUser
    zgBtnNextPageRes(data){
      const params = {
        prjId: this.zgPrjList.failPrjList?.map(item => item.prjId).join(','),
        sceneCode:'SC_ACC_ZG_001',
        currentUserId:data.empId||this.newPrjDetail?.projectManagerLoginName,
        staffId:data.code ||this.newPrjDetail?.projectManager
      }
      getSelectUser(params).then(res => {
        if (+res.code === 200) {
          clonePage()
        }
      })
    },
    nextPageRes(data) {
      if(this.zgPrjList.confirm === 'Z'){
        this.zgBtnNextPageRes(data)
        return
      }
      console.log(data)
      const prjId = this.prjInfos.map(item => item.prjId).join(',')
      const workItemIds = this.prjInfos.map(item => item.workItemId).join(',')
      const params = {
        'prjId': prjId,
        'workItemIds': workItemIds,
        'userIds': data.empId,
        'route': '1', // 下一步页面
        'wfXpath': [], // 暂时不传
        'opinion': data.opinion,
        'nextSceneId': data.nextSceneId, // 先不传
        'nodeId': data.nodeId,
        'detailId': data.detailId, // 先不传
        'route1': '1', // 决算页面
        'activityDefId': data.actDefId, // 当前节点
        'finish': data.finish, // 当前节点
        'templateId': data.nTemplateId
      }
      doNextBatchFLowApi(params).then(res => {
        if (+res.code === 200) {
          if (this.newPrjDetail.manageMode == '31') {
            clonePage()
          } else {
            this.$message.success('操作成功')
            this.$emit('getTable')
          }
        }
      })
    },
    // 维护改造类优化代码2021/10/24
    optimizeprefixCheckOne() {
      let results = JSON.parse(window.sessionStorage.getItem('TableprjInfos')) || []
      return results
    },
    optimizeprefixCheckTwo(_tablesinfo) {
      return !(_tablesinfo[0]?.prjType === 'W' && this.newPrjDetail.buildModes === '26')
    },
    optimizeprefixCheckThree(SingeZhengti,_tablesinfo) {
      if(this.newPrjDetail.ifOnlineServ === '0'){
        return this.optimizeIfSolveThree(_tablesinfo)
      }else{
        return this.newPrjDetail.manageMode === '01' ? this.optimizeIfSolveTwoNengYuan() : SingeZhengti
      }
    },
    //  单站-能源
    optimizeIfSolveTwoNengYuan(){
      return !(this.newPrjDetail.prjType === 'W' && this.newPrjDetail.buildModes === '26')
    },
    optimizeIfSolveThree(_tablesinfo) {
      if (this.newPrjDetail.manageMode === '01' && this.newPrjDetail.prjType === 'W' && this.newPrjDetail.buildModes === '25') {
        return false
      }
      if (_tablesinfo[0]?.prjType === 'W' && _tablesinfo[0]?.buildModes === '25') {
        return false
      }
    },
    optimizeprefixCheckFour(isHiddenMatria) {
      return +this.materialsCode !== 200 && isHiddenMatria && this.newWorkDetail?.bizObject?.bizState === 'F1'
    },
    optimizeprefixCheckFive() {
      return this.saveCreateCheck.id === 'apply' || this.saveCreateCheck.id === 'createCheck' || this.saveCreateCheck.id === 'maintenance'
    },
    async optimizeprefixCheckSix(params) {
      this.zgPrjList = []
      const result = await executeVerificationApi(params)
      if (+result.code === 200) {
        await this.prefixCheck()
        return
      }
      // 弱校验提示
      if (result.data.confirm === 'P') {
        this.loading.close()
        this.currentParams = result.data.data
        this.dialogMessage = result.message
        this.dialogVisible2 = true
        throw ''
      }
      if (result.data.confirm === 'B') { // 回退
        msgInfoEl({
          type: 'error',
          message: result.message
        }, 3000)
        this.excludeActDefIds = result.data.excludeActDefIds
        this.backVisible = true
        throw ''
      }
       // 项目接维 打开下一步
       if (this.newWorkDetail?.bizObject?.bizState === 'F12'&&result.data.confirm === 'Z') {
        this.zgPrjList = result.data
        this.nextVisible = true
        throw ''
      }
      msgInfoEl({
        type: 'error',
        message: result.message
      }, 3000)
      throw ''
    },
    async prefixCheck() {
      this.checkMaterials = false
      const { data, ysCode } = this.checkList
      if (!data?.length) {
        const check = this.selectList.some(item => !['F1'].includes(item.nodeState))
        const _tablesinfo = this.optimizeprefixCheckOne()
        const SingeZhengti = this.optimizeprefixCheckTwo(_tablesinfo)
        // 单站的内部验收和整体内部验收不一样
        const isHiddenMatria = this.optimizeprefixCheckThree(SingeZhengti,_tablesinfo)
        // 内验首先弹出物资总览查看新页面=>在下一步以后才可以打开校验清单页面
        if (this.optimizeprefixCheckFour(isHiddenMatria)) {
          this.checkMaterials = true
          this.checkDialog = true
          return
        }
        if (!check) {
          this.checkDialog = true
        }
        if (this.optimizeprefixCheckFive()) {
           this.checkOpenCreateCheckDialog();
        }
        return
      }
      this.currentCheck = data.shift()
      const params = {
        'prjInfos': this.prjInfos,
        'code': this.currentCheck.code,
        'operateFlag': 1,
        'ysCode': ysCode
      }
      await this.optimizeprefixCheckSix(params)
    },
    getEquipmentChangeParams(){
        const list=[]
        for (let i = 0; i < this.selectList?.length; i++) {
            list.push(this.selectList[i]?.prjId)
        }
        const params={
            prjId:this.selectList[0]?.parentPrjId,
            ifSingleProject: '1',
            subPrjIds:list,
        }
        return params;
    },
    checkOpenCreateCheckDialog(){
        if(this.newPrjDetail.isNewBusiness === '0' && this.newPrjDetail.businessMajor === '04' && this.saveCreateCheck.id === 'createCheck' && ['F5','F12'].includes(this.newWorkDetail?.bizObject?.bizState)){
            console.log('发起内验按钮类型是next，但是满足维护专业，资源确认节点时，显示设备变更弹窗，所以此时nextVisible不能为true',this.selectList)
            const params=this.getEquipmentChangeParams();
            getShowEquipmentChangeApi(params).then((res)=>{
                if(+res.code === 200){
                    if(res.data?.length > 0){
                        // this.equipmentPrjIds = res.data;
                        window.sessionStorage.setItem('equipmentPrjIds', JSON.stringify(res.data))
                        this.dialogPage = 'equipmentChange'
                        this.dialogTitle = '设备变动信息'
                        this.dialogVisible = true
                        this.dialogWidth=90
                    }else{
                        this.nextVisible = true
                    }
                }
            })
        }else{
            this.nextVisible = true
        }
    },
    async dialogSubmit() {
      this.dialogVisible2 = false
      this.loading = Loading.service({
        lock: true,
        text: '正在处理,请稍后',
        spinner: 'el-icon-loading'
      })
      const params = {
        prjInfos: this.currentParams,
        code: this.currentCheck.code,
        operateFlag: 1,
        ysCode: this.checkList.ysCode
      }
      try {
        const result = await executeFailureToUpdateApi(params)
        if (+result.code === 200) {
          this.prefixCheck()
        }
      } finally {
        this.loading.close()
      }
    },
    // 插入数组的prjid
    insertPrjIdList(list, type, name) {
      const arrList = []
      // 整体项目默认 单项工程 取传递的值
      const typeName = type === '03' ? '' : name
      for (let i = 0; i < list.length; i++) {
        arrList.push(list[i].prjId)
      }
      return {
        arrList,
        typeName
      }
    },
    entiretyChange() {
      const _selectListPrjids = []
      if (this.newPrjDetail.manageMode === '01') {
        return _selectListPrjids
      }
      const _tableData = JSON.parse(window.sessionStorage.getItem('TableprjInfos')) || []
      let resultList = this.selectList.length > 0 ? this.selectList : _tableData
      for (let i = 0; i < resultList?.length; i++) {
        _selectListPrjids.push(resultList[i]?.prjId)
      }
      return _selectListPrjids
    },
    // 维护改造 完工 开工
    async commenCement(item) {
      let _status = item.id === "projectStart" ? 'E2' : 'E0'
      const _selectListPrjids = this.entiretyChange()
      // 单站
      const singleParams = {
        prjIds: this.prjId,
        state: _status,
      }
      // 整体
      const entiretyParams = {
        prjIds: _selectListPrjids.join(','),
        state: _status,
      }
      // 单站
      if (this.newPrjDetail.manageMode === '01') {
        await this.confirmCompletion(singleParams)
      } else {
        // 整体项目 没有勾选默认全选，勾选了选勾选的
        await this.confirmCompletion(entiretyParams)
      }
    },
    async confirmCompletion(params) {
      console.log(params);
      const {code,message} = await getStartEndWork(params)
      if(+code===200){
        this.$message.success(message)
      }
    },
    async optimizeNewhandleClickOne_One(item) {
      if (['serviceEdit', 'materialBinding'].includes(item.id)) {
        this.isEdit = '1'
      } else {
        this.isEdit = '0'
      }
    },
   async optimizeNewhandleClickOne_Two(item){
    if (['siteList', 'materialBinding', 'materialService', 'serviceEdit', 'serviceShow', 'materialShow', 'materialServiceShow','equipmentChange'].includes(item.id)) {
          this.dialogWidth = 90
        } else {
          this.dialogWidth = 50
        }
   },
    async optimizeNewhandleClickOne(item, params,newParams) {
      if (item.type === 'dialog') {
        await this.optimizeNewhandleClickOne_One(item)
        await this.optimizeNewhandleClickOne_Two(item)
        this.dialogPage = item.url
        this.dialogTitle = item.title
        this.dialogVisible = true
        if (['materialShow'].includes(item.id)) {
          this.$nextTick(() => {
            this.dialogEl('accDialog')
          })
        }
      }
      await this.optimizeNewhandleClickTwo(item, params,newParams)
    },
    checkCreateCheckNext(item){
        if(this.newPrjDetail.isNewBusiness === '0' && this.newPrjDetail.businessMajor === '04' && item.id==='createCheck'&&this.newWorkDetail?.bizObject?.bizState === 'F5'){
            console.log('发起内验按钮类型是next，但是满足维护专业，资源确认节点时，显示设备变更弹窗，所以此时nextVisible不能为true',this.selectList)
            const params=this.getEquipmentChangeParams();
            getShowEquipmentChangeApi(params).then((res)=>{
                if(+res.code === 200){
                    if(res.data?.length > 0){
                        //此时next应该是打开下一步弹窗，但是满足打开设备弹窗时，就啥也不干
                    }else{
                        this.nextVisible = true
                    }
                }
            })
        }else{
            this.nextVisible = true
        }
    },
    // 批量资源录入
    async batchOperationEntering(url, params1, params2) {
      let res;
      let _deepParams = params2
      if (this.newPrjDetail.manageMode === '01') {
        _deepParams.subPrjIdList = [params1.prjId]
        _deepParams.nodeName = this.newWorkDetail.activityInstName
      }
      res = await getGoToMultipleMateApi(url, _deepParams)
      return res;
    },
    // 批量资源确认
    async batchOperationConfirmation(items, params1, params2){
      let res;
      let _deepParams = params2
      if (this.newPrjDetail.manageMode === '01') {
        _deepParams.subPrjIdList = [params1.prjId]
      }
      // 整体 单项工程 资源确认批量接口
      if (['01','03', '31'].includes(this.newPrjDetail.manageMode) && items.id === "materialAffirm") {
        res = await getGoToMultiplApi(items.url, _deepParams.subPrjIdList)
      } else {
        //如果是查看验工计价，传的参数可能是选中数据的prjId
        console.log(items,params1,this.selectList)
        const params = items.id === 'checkValuation'?{prjId:this.selectList[0].prjId}:params1
        res = await getGoToApi(items.url, params)
      }
      return res;
    },
    async optimizeNewhandleClickTwo(item, params,newParams) {
      if (item.type === 'next') {
          this.checkCreateCheckNext(item);
      }
      if (item.type === 'form') {
        this.checkDialog = true
      }
      // 跳转到其他系统
      if (item.type === 'goto') {
        console.log("批量2===>",params,newParams);
        let res
        if (item.id === 'entering') {
          res = await this.batchOperationEntering(item.url, params,newParams)
        } else {
          res = await this.batchOperationConfirmation(item, params,newParams)
        }
        if (+res?.code !== 200) {
          return
        }
        await this.optimizeNewhandleClickThree(item, res)
      }
      await this.optimizeNewhandleClickFour(item, params)
    },
    async optimizeNewhandleClickThree(item, res) {
      if (['entering', 'materialAffirm'].includes(item.id)) {
        const params2 = {}
        params2.pwdaToken = res.data.pwdaToken
        params2.acctId = res.data.acctId
        newOpenPostWindow(res.data.jumpUrl, {}, res.data.isNew)
      } else if (item.id === 'costSheet') {
        const today = new Date()
        const year = today.getFullYear()
        const month = today.getMonth() + 1 // 注意，getMonth()方法返回月份是从0开始的，所以需要加1
        const day = today.getDate()
        const endTime = year + '-' + month + '-' + day
        const params = {}
        params.pwdaToken = res.data.pwdaToken
        params.acctId = res.data.acctId
        params.Login = 'PMS_ZP'
        params.flag = '1'
        params.ENDTIME = endTime
        params.STARTTIME = '2015-01-01'
        params.XMBH = res.data.prjCode
        params.DWBH = res.data.orgCode
        newOpenPostWindow(res.data.jumpUrl, params)
      } else if (['maintain2', 'maintain3', 'maintain4'].includes(item.id)) {
        const params1 = {}
        params1.pwdaToken = res.data.pwdaToken
        params1.acctId = res.data.acctId
        newOpenPostWindow(res.data.jumpUrl, params1)
      } else {
        window.open(res.data.jumpUrl)
      }
    },
    async optimizeNewhandleClickFour(item, params) {
      if (item.type === 'message') {
        if (item.url === 'threeSingleMatch') {
          threeSingleMatchApi(params).then(res => {
            if (+res.code === 200) {
              this.$message.success(res.message)
            }
          })
        }
      }
    },
    async optimizeNewhandleClickFive(item) {
      if (['serviceEdit'].includes(item.id)) {
        const params_ = {
          'configFlag': '1',
          'prjId': this.prjId
        }
        const check = await checkSerDetailsConfigApi(params_)
        if (+check.code !== 200) {
          return Promise.reject()
        }
      }
    },
    async optimizeNewhandleClickSix(item) {
      if (['materialBinding', 'materialService'].includes(item.id)) {
        const params = {
          'subPrjList': this.selectList.map(_item => _item.prjId),
          'currentNodeName': this.selectList[0].opioionNodeName,
          'configFlag': this.newPrjDetail.manageMode === '31' ? 'single' : 'overall',
          'operButten': item.id === 'materialBinding' ? '101' : '201'
        }
        const check = await beforeProdBindCheckApi(params)
        if (+check.code !== 200) {
          return Promise.reject()
        }
      }
    },
    async optimizeNewhandleClickSeven(item) {
      if (item.id === 'check') {
        const check = this.selectList.some(_item => !['F1'].includes(_item.nodeState))
        if (check) {
          this.$message.warning('仅支持对处于内部验收节点项目进行操作，请重新选择！')
          return Promise.reject()
        }
        await this.prefixCheckList()
      }
    },
    async optimizeNewhandleClickEight(item) {
      if (item.id === 'createCheck') {
        if (this.selectList.length > 30) {
          this.$message.warning('最大可支持对30个项目提交流程，请重新选择。')
          return Promise.reject()
        }
        const check = this.selectList.some(_item => !['F5'].includes(_item.nodeState))
        if (check) {
          this.$message.warning('仅支持对处于资源确认节点项目进行操作，请重新选择！')
          return Promise.reject()
        }
        await this.prefixCheckList()
      }
    },
    async optimizeNewhandleClickNine(item) {
      if (item.id === 'apply'||item.id === 'maintenance') {
        if (this.selectList.length > 30) {
          this.$message.warning('最大可支持对30个项目提交流程，请重新选择。')
          return Promise.reject()
        }
        await this.prefixCheckList()
      }
    },
    async optimizeNewhandleClickTen(item) {
      if (['serviceEdit'].includes(item.id)) {
        const params = {
          'configFlag': '2',
          'prjId': this.newPrjDetail.manageMode === '31' ? this.newPrjDetail.parentPrjId : this.prjId,
          'operateFlag': this.newPrjDetail.manageMode === '03' ? 'overall' : 'single',
          'subPrjList': this.selectList.map(_item => { return { prjId: _item.prjId, nodeName: _item.opioionNodeName } })
        }
        const check = await checkSerDetailsConfigApi(params)
        if (+check.code !== 200) {
          return Promise.reject()
        }
      }
    },
    async optimizeNewhandleClickEleve(item) {
      if (['materialBinding', 'materialService', 'serviceEdit', 'entering', 'apply'].includes(item.id)) {
        // 智联无实施 单项工程/整体项目 03  311
        let check = this.selectList.some(_item => !['F4', 'E5',null].includes(_item.nodeState))
        if (this.newPrjDetail.isNewBusiness === '1' && this.newPrjDetail.ifNewStartupProcess === '1' && ['03', '31'].includes(this.newPrjDetail.manageMode)) {
          check = false
        }
        console.log(this.selectList)
        if (check) {
          const ms = this.newPrjDetail.manageMode !== '31' ? '完工审批/' : ''
          this.$message.warning(`仅支持对处于${ms}资源录入节点项目进行操作，请重新选择！`)
          return Promise.reject()
        }
      }
    },
    async optimizeNewhandleClickTweleve(ifStartAccProcess) {
      if (ifStartAccProcess) {
        this.$message.warning('仅支持对验收流程状态为发起成功的项目进行操作,请先在单项工程列表中点击[发起流程]按钮!')
        return Promise.reject()
      }
    },
    async optimizeNewhandleClickThirteen() {
      if (this.type !== '1') {
        this.$message.warning('请选择数据')
        return Promise.reject()
      }
    },
    async optimizeNewhandleClickFourteen(item) {
      let result = this.prjId
      if (item.id == 'costSheet') {
        result = this.newPrjDetail.prjId
      }
      return result
    },
    async optimizeNewhandleClickFiveteen() {
      if (this.selectList.length !== 1) {
        this.$message.warning('仅支持勾选一条数据进行操作')
        return Promise.reject()
      }
    },
    getNewInsertList(){
      const { arrList, typeName } = this.insertPrjIdList(this.selectList, this.newPrjDetail.manageMode, this.newWorkDetail.activityInstName)
      return {
        arrList,
        typeName
      }
    },
    async checkClick(item) {
        if (['51', '05'].includes(this.newPrjDetail.manageMode)) {
            if(item.id === 'check' && this.selectList.length === 0 && this.type !== '1'){
                this.$message.warning('请选择数据')
                return Promise.reject()
            }else if(item.id === 'checkValuation' && this.selectList.length !== 1 ){
                this.$message.warning('请选择一个子项目进行操作！')
                return Promise.reject()
            }else{
                console.log('啥也不干')
            }
        }
    },
    async checkClickAcceptTime(item){
      console.log(111233,item.id,this.type,this.newPrjDetail.manageMode,this.selectList)
      if(item.id === 'check' && this.type !== '1' && this.newPrjDetail.manageMode === '51'){
        let acceptTimeDate=window.sessionStorage.getItem('acceptTimeDate')
        if(!acceptTimeDate){
          this.$message.error('请选择对应的时间')
          return Promise.reject()
        }else{
          let list=[];
          for (let i = 0; i < this.selectList?.length; i++) {
            list.push(this.selectList[i]?.prjId)
          }
          const params={
            prjId:list.join(),
            endInternalAcceptDate:acceptTimeDate
          }
          const { code } = await updateAcceptTimeApi(params)
          if (+code !== 200) {
            // this.$message.error('校验失败')
            return Promise.reject()
          }
        }
      }
    },
    async handleClick(item, shows = false) {
      this.show = shows
      const params = {
        prjId: this.prjId
      }
      const newParams = {
        subPrjIdList: [],
        nodeName: '资源录入'// 整体父项目默认
      }
      this.saveCreateCheck = item
      if (item.type === 'projectCheck') {
        this.commenCement(item)
        return
      }
      await this.checkClick(item);
      await this.checkClickAcceptTime(item);
      // 整体项目节点
      if (['31', '03'].includes(this.newPrjDetail.manageMode)) {
        if (!['siteList', 'materialServiceShow'].includes(item.id) && this.selectList.length === 0) {
          await this.optimizeNewhandleClickThirteen()
          // VR
          this.selectList = [{ prjId: this.newPrjDetail.prjId, ifStartAccProcess: 1 }]
          // 成本单
          params.prjId = this.optimizeNewhandleClickFourteen(item)
        }
        const ifStartAccProcess = this.selectList.some(_item => _item.ifStartAccProcess != 1)
        await this.optimizeNewhandleClickTweleve(ifStartAccProcess)
        await this.optimizeNewhandleClickEleve(item)
        await this.optimizeNewhandleClickTen(item)
        if (['entering', 'panorama', 'materialAffirm'].includes(item.id)) {
          // await this.optimizeNewhandleClickFiveteen()
          // params.prjId = this.selectList[0].prjId
          const { arrList, typeName } = this.getNewInsertList()
          newParams.subPrjIdList = arrList
          newParams.nodeName = typeName
          console.log(arrList, typeName, "批量1===>", newParams);
        }
        await this.optimizeNewhandleClickNine(item)
        await this.optimizeNewhandleClickEight(item)
        await this.optimizeNewhandleClickSeven(item)
        await this.optimizeNewhandleClickSix(item)
      } else {
        await this.optimizeNewhandleClickFive(item)
      }
      this.item = item

      // 打开弹框
      await this.optimizeNewhandleClickOne(item, params,newParams)
    },
    changeMsg(status) {
      this.dialogVisible2 = false
      if (status) {
        this.dialogSubmit()
      }
    },
    // 关闭弹框提示消息不销毁问题
    closeDialog() {
      const body = document.body
      const _message = body.getElementsByClassName('el-message')
      if (_message && _message.length > 0) {
        for (let i = 0; i < _message.length; i++) {
          body.removeChild(_message[i])
          this.closeDialog()
        }
      } else {
        this.checkDialog = false
        this.materialsCode = ''
      }
    },
    // 关闭查看物资总览弹框
    closeMaterialsDialog() {
      const body = document.body
      const _message = body.getElementsByClassName('el-message')
      if (_message && _message.length > 0) {
        for (let i = 0; i < _message.length; i++) {
          body.removeChild(_message[i])
          this.closeMaterialsDialog()
        }
      } else {
        this.dialogVisible = false
        this.materialsCode = ''
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.acc-button {
  .btn {
    color: #000000;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: right;
  }

  .acc-item {
    cursor: pointer;
    white-space: nowrap;
    margin-left: 10px;
    font-size: 12px;
    line-height: 30px;
    height: 30px;
    background: rgb(235, 75, 75);
    padding: 5px 15px;
    color: #ffffff;
    border-radius: 2px;
  }
}
</style>
